<!-- add.html文件 -->
<#include "../common/scripts.html">
<#include "../common/scripts_add.html">
<#include "../common/scripts_add2.html">


<style type="text/css">

	/*禁用样式*/
	button[disabled], html input[disabled], textarea[disabled] {
		cursor: not-allowed;
	}

	.ewm {
		position: absolute;
		right: 0px;
		bottom: -150px;
		text-align: right;
		display: none;
		z-index: 100;
		border: 1px solid;
	}

	.apk-ma-little:hover .ewm {
		display: block;
	}

	.div-main {
		min-width: 1300px;
	}

	.redidual-ratio-question-tooltip {
		display: none;
	}

	.redidual-ratio-question-mark:hover + .redidual-ratio-question-tooltip {
		display: block;
	}


	.div-main {
		padding-bottom: 0px;
	}

	#extInfo {
		display: none;
	}

	input.attr-control[type='radio'], input.attr-control[type='checkbox'] {
		width: auto;
		vertical-align: top;
	}

	input.attr-control[type='radio'] + label, input.attr-control[type='checkbox'] + label {
		margin-bottom: 0;
	}

	.glyphicon-folder-open:before {
		margin-right: 5px;
	}

	.glyphicon-open:before {
		margin-right: 2px;
	}

	.glyphicon-plus:before {
		margin-right: 2px;
	}

	/* 表格样式 */
	/*
	table>thead>tr>th, table>thead>tr>td, table>tbody>tr>td {
		text-align: center;
		vertical-align: middle;
		white-space: nowrap;
		font-weight: normal;
	}*/

	/* 相关文件》表格样式 */
	.file-name-container table tr th, .file-name-container table tr td {
		text-align: center;
		font-weight: normal;
	}

	/* table-main-2相关样式 */
	.table-main-2 {
		table-layout: fixed;
		word-break: break-all;
	}

	.table-main-2 th {
		border: 1px solid #DBF4FF;
		color: #0CB3FE;
	}

	.table-main-2 td {
		border: 1px solid #ccc;
	}

	.table-main-2 tr td:nth-child(odd) {
		text-align: center;
		width: 10% !important;
	}

	.table-main-2 tr td:nth-child(even) {
		width: 30% !important;
	}


</style>


<!--岗位信息 -->
<form action="" method="post" id="addForm" class="form-horizontal" style="padding-bottom: 96px;">
	<input type="hidden" id="id" name="id" value="${(postGroup.id)!}" class="">
	
	<!--左侧数据 -->
	<div class="leftdata" style="min-height: 415px; width: 90%;">
		
		<!-- 基础信息 -->
		<div class="form-group" style="">
			<div class="fh-subtitle" style="overflow: hidden; line-height: 32px;">
				岗位信息
			</div>
			
			<table id="tab_basic" style="width: 100%; border-collapse: collapse;" class="table-main-2">
				<tbody>
				<tr>
					<td><span class="required-flag">*</span><span>公司名称</span></td>
					<td>
						<input type="text" id="companyName" name="companyName" class="form-control-gx"
							   value="${(postGroup.companyName)!}" readonly>
					</td>
					
					<td><span class="required-flag">*</span><span>公司编号</span></td>
					<td>
						<input type="text" id="companyCode" name="companyCode" class="form-control-gx"
							   value="${(postGroup.companyCode)!}" readonly>
					</td>
				</tr>
				
				<tr>
					<td><span>上级名称</span></td>
					<td><input type="text" id="parentPostName" name="parentPostName" class="form-control-gx"
							   value="${(postGroup.parentPostName)!}" onclick="getParentPostName()" readonly>
						<input type="hidden" id="parentId" name="parentId" class="form-control-gx" value="${(postGroup.parentId)!}" readonly>
					</td>
					
					<td><span>上级编码</span></td>
					<td><input type="text" id="parentPostCode" name="parentPostCode" class="form-control-gx"
							   value="${(postGroup.parentPostCode)!}" readonly></td>
				</tr>
				
				<tr>
					<td><span class="required-flag">*</span><span>名称</span></td>
					<td><input type="text" id="postName" name="postName" class="form-control-gx"
							   value="${(postGroup.postName)!}"></td>
					
					<td><span class="required-flag">*</span><span>编号</span></td>
					<td><input type="text" id="postCode" name="postCode" class="form-control-gx"
							   value="${(postGroup.postCode)!}"></td>
				</tr>
				
				<tr>
					<td><span>排序</span></td>
					<td colspan="3"><input type="text" id="sort" name="sort" class="form-control-gx"
										   value="${(postGroup.sort)!}"></td>
				</tr>
				</tbody>
			</table>
		</div>
	</div>
	
	<!-- 清除浮动 -->
	<div class="clear-both"></div>
	
	<!--底部按钮 -->
	<div style="width: 100%; height: 40px; margin: 20px 0px 28px;">
		<div style="margin-top: 5px; text-align: center; width: 94%;">
			<button type="button" id="btn_submit" onclick="submit_authority()" class="btn btn-default"
					style="width: 90px; background-color: #66C9B7; color: #ffffff;">提交
			</button>
		</div>
	</div>
</form>


<script type="text/javascript" src="${static}/page/back/customprint/file/cpTemple.js"></script>
<script type="text/javascript" src="${static}/page/back/device/js/img.js"></script>
<script src="${static}/js/custome-attr-utils.js"></script>

<script type="text/javascript">
	
	$(document).ready(function () {
		//渲染选择框
		$(".selectpicker").select2();
		
	});
	
	$(function () {
	
	});
	
	/**
	 * 获取上级编码。
	 * @deprecated 待删
	 * @param
	 * @return
	 * @author cjw 2020-04-13
	 */
	function getParentName_0() {
		var nodeNames = [];
		PullDownTree_obj.init("${ctx}/authority/getAuthorityTree", "#parentName",
			{}, "#parentCode", false, "", "", function (treeId, treeNode) {
				getParent(treeNode);
				$("#parentName").val(nodeNames.join("/"));
				$("#parentName").parent().prop("title", nodeNames.join("/"));
				$("#parentCode").val(treeNode.value);
				$("#ztree-container").hide();
				return false;
			});
		
		function getParent(treeNode) {
			var parentNode = treeNode.getParentNode();
			if (parentNode != null) {
				getParent(parentNode);
			}
			nodeNames.push(treeNode.name);
		}
	}
	
	/**
	 * 获取上级岗位名称等信息。
	 * @param
	 * @return
	 * @author cjw 2020-04-11
	 */
	function getParentPostName() {
		PullDownTree_obj.init("${ctx}/postGroup/getPostGroupTree", "#parentPostName",
			{companyCode: "${(postGroup.companyCode)!}"}, "#parentId", false,
			function (v, info) {
				$("#parentId").val(info.id);
				$("#parentPostCode").val(info.value);
			});
	}
	
	//弹出layer窗口
	function window1(icon, title, url, width, heigth, type) {
		var title2 = title;
		if (!isEmpty(icon)) {
			title2 = '<img src="' + icon + '" width="20"/>' + title;
		}
		layer.open({
			type: 2,
			title: title2,
			maxmin: true,
			shadeClose: false, //点击遮罩层关闭
			shade: [0.1, '#fff'],
			area: [width + "", heigth + ""],
			offset: ['10px'],
			fixed: false,
			content: url
		});
	}
	
	/**
	 * 提交菜单权限信息。
	 * @param
	 * @return
	 * @author cjw 2020-03-31
	 */
	function submit_authority() {
		
		/**
		 * 验证填写的信息是否完整。
		 */
		if (isEmpty_byJqObj($("#companyCode"))) {
			sys.msg({
				"msg": "请填写companyCode!"
			});
			return false;
		}
		if (isEmpty_byJqObj($("#postName"))) {
			sys.msg({
				"msg": "请填写岗位名称!"
			});
			return false;
		}
		if (isEmpty_byJqObj($("#postCode"))) {
			sys.msg({
				"msg": "请填写岗位编码!"
			});
			return false;
		}
		
		/**
		 * 验证填写的信息是否有效。
		 */
		
		/**
		 * 提交岗位信息
		 */
		var submitData = $("#addForm").serialize();
		console.log("submitData=", submitData);
		
		//若id为空,存入该postGroup。
		if (isEmpty_byJqObj($("#id"))) {
			sys.getApiData("addPostGroup", submitData, function (data2) {
				//console.log("addAssetsArchive.response.data2", data2);
				if (data2.success) {
					js.showMessage("新增岗位成功!", null, "success", 1500);
					js.closeCurrentTabPage(function (contentWindow) {
						contentWindow.search();
					});
				} else {
					js.showMessage(data2.message, null, "error", 1500);
				}
			});
		} else {
			//若id不为空,更新该postGroup。
			sys.getApiData("updatePostGroup", submitData, function (data2) {
				//console.log("addAssetsArchive.response.data2", data2);
				if (data2.success) {
					js.showMessage("更新岗位成功!", null, "success", 1500);
					js.closeCurrentTabPage(function (contentWindow) {
						contentWindow.search();
					});
				} else {
					js.showMessage(data2.message, null, "error", 1500);
				}
			});
		}
	}
	
	/**
	 * 验证填写的code,name是否有效。
	 * @param
	 * @return
	 * @author cjw 2020-05-07
	 */
	function checkCodeAndName() {
		var isValid = true;
		
		$.ajax({
			url: "${ctx }/authority/checkCodeAndName",
			type: "POST",
			datatype: "json",
			data: {
				id: $("#id").val(),
				code: $("#code").val(),
				name: $("#name").val(),
				applicationId: $("#applicationId").val()
			},
			success: function (data2, stats) {
				if (data2.success) {
					//若验证有效
				} else {
					isValid = false;
					sys2.msg(data2);
				}
			},
			error: function (data2) {
				isValid = false;
				sys2.msg({message: "检查code,name有效性时,出错!"})
			}
		});
	}
	
	
</script>

